﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using AutoR.Models;
using AutoR.Services;
using AutoR.Tasks;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;
using Xamarin.Forms;

namespace AutoR.ViewModels.Tasks
{
	// Token: 0x02000071 RID: 113
	public class AttackTaskSettingViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x1700005E RID: 94
		// (get) Token: 0x060001C3 RID: 451 RVA: 0x000444E1 File Offset: 0x000426E1
		private INavigationService NavigationService { get; }

		// Token: 0x1700005F RID: 95
		// (get) Token: 0x060001C4 RID: 452 RVA: 0x000444E9 File Offset: 0x000426E9
		private IPageDialogService PageDialogService { get; }

		// Token: 0x17000060 RID: 96
		// (get) Token: 0x060001C5 RID: 453 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x17000061 RID: 97
		// (get) Token: 0x060001C6 RID: 454 RVA: 0x000444F1 File Offset: 0x000426F1
		public AllConfigs Configs
		{
			get
			{
				return Runtime.Configs;
			}
		}

		// Token: 0x17000062 RID: 98
		// (get) Token: 0x060001C7 RID: 455 RVA: 0x000444F8 File Offset: 0x000426F8
		// (set) Token: 0x060001C8 RID: 456 RVA: 0x00044500 File Offset: 0x00042700
		public AttackTask Task
		{
			[CompilerGenerated]
			get
			{
				return this.<Task>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Task>k__BackingField, value))
				{
					return;
				}
				this.<Task>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Task);
			}
		}

		// Token: 0x17000063 RID: 99
		// (get) Token: 0x060001C9 RID: 457 RVA: 0x00044530 File Offset: 0x00042730
		public DelegateCommand LevelListCommand { get; }

		// Token: 0x17000064 RID: 100
		// (get) Token: 0x060001CA RID: 458 RVA: 0x00044538 File Offset: 0x00042738
		public DelegateCommand<AttackNode> NodeListCommand { get; }

		// Token: 0x17000065 RID: 101
		// (get) Token: 0x060001CB RID: 459 RVA: 0x00044540 File Offset: 0x00042740
		public DelegateCommand AddNodeCommand { get; }

		// Token: 0x17000066 RID: 102
		// (get) Token: 0x060001CC RID: 460 RVA: 0x00044548 File Offset: 0x00042748
		public DelegateCommand RemoveNodeCommand { get; }

		// Token: 0x17000067 RID: 103
		// (get) Token: 0x060001CD RID: 461 RVA: 0x00044550 File Offset: 0x00042750
		public DelegateCommand AddRuleCommand { get; }

		// Token: 0x17000068 RID: 104
		// (get) Token: 0x060001CE RID: 462 RVA: 0x00044558 File Offset: 0x00042758
		public DelegateCommand OpenJSCommand { get; }

		// Token: 0x17000069 RID: 105
		// (get) Token: 0x060001CF RID: 463 RVA: 0x00044560 File Offset: 0x00042760
		public DelegateCommand OnUploadCommand { get; }

		// Token: 0x1700006A RID: 106
		// (get) Token: 0x060001D0 RID: 464 RVA: 0x00044568 File Offset: 0x00042768
		public DelegateCommand<AttackNode> TypeCommand { get; }

		// Token: 0x1700006B RID: 107
		// (get) Token: 0x060001D1 RID: 465 RVA: 0x00044570 File Offset: 0x00042770
		public DelegateCommand<AttackNode> RemoveCommand { get; }

		// Token: 0x1700006C RID: 108
		// (get) Token: 0x060001D2 RID: 466 RVA: 0x00044578 File Offset: 0x00042778
		public DelegateCommand<IList<int>> FleetCommand { get; }

		// Token: 0x1700006D RID: 109
		// (get) Token: 0x060001D3 RID: 467 RVA: 0x00044580 File Offset: 0x00042780
		public DelegateCommand<IList<string>> TacticsCommand { get; }

		// Token: 0x1700006E RID: 110
		// (get) Token: 0x060001D4 RID: 468 RVA: 0x00044588 File Offset: 0x00042788
		public DelegateCommand<IList<ShipType>> RuleTypeCommand { get; }

		// Token: 0x1700006F RID: 111
		// (get) Token: 0x060001D5 RID: 469 RVA: 0x00044590 File Offset: 0x00042790
		public DelegateCommand<RuleFleet> RuleRemoveCommand { get; }

		// Token: 0x17000070 RID: 112
		// (get) Token: 0x060001D6 RID: 470 RVA: 0x00044598 File Offset: 0x00042798
		public DelegateCommand<RuleFleet> EquipmentCommand { get; }

		// Token: 0x17000071 RID: 113
		// (get) Token: 0x060001D7 RID: 471 RVA: 0x000445A0 File Offset: 0x000427A0
		public DelegateCommand<RuleFleet> VisCommand { get; }

		// Token: 0x060001D8 RID: 472 RVA: 0x000445A8 File Offset: 0x000427A8
		public AttackTaskSettingViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
		{
			this.NavigationService = navigationService;
			this.PageDialogService = pageDialogService;
			this.AddNodeCommand = new DelegateCommand(delegate()
			{
				this.Task.AttackNode.Add(new AttackNode());
			});
			this.RemoveNodeCommand = new DelegateCommand(new Action(this.OnRemoveNodeCommandExecuted));
			this.AddRuleCommand = new DelegateCommand(new Action(this.OnAddRuleCommandExecuted));
			this.OnUploadCommand = new DelegateCommand(new Action(this.OnUploadCommandExecuted));
			this.LevelListCommand = new DelegateCommand(async delegate()
			{
				string[] otherButtons = (from i in this.Configs.PVEConfig.PVELevel
				select i.Name).ToArray<string>();
				string ss2 = await this.PageDialogService.DisplayActionSheetAsync("", "取消", null, otherButtons);
				string ss = ss2;
				if (ss != null && ss != "取消")
				{
					PVELevel pvelevel = this.Configs.PVEConfig.PVELevel.Single((PVELevel i) => i.Name == ss);
					this.Task.NodeID = pvelevel.id;
				}
			});
			this.NodeListCommand = new DelegateCommand<AttackNode>(async delegate(AttackNode node)
			{
				string[] otherButtons = (from i in Runtime.Configs.PVEConfig.PVENode
				where i.pveLevelId == this.Task.NodeID && i.flag != ""
				select i.flag).ToArray<string>();
				string text = await this.PageDialogService.DisplayActionSheetAsync("", "取消", null, otherButtons);
				if (text != null && text != "取消")
				{
					node.Node = text;
				}
			});
			this.OpenJSCommand = new DelegateCommand(delegate()
			{
				Device.OpenUri(new Uri("http://js.ntwikis.com"));
			});
			this.TypeCommand = new DelegateCommand<AttackNode>(async delegate(AttackNode node)
			{
				NavigationParameters parameters = new NavigationParameters
				{
					{
						"node",
						node
					}
				};
				await this.NavigationService.NavigateAsync("NodeCondition", parameters);
			});
			this.RemoveCommand = new DelegateCommand<AttackNode>(delegate(AttackNode node)
			{
				this.Task.AttackNode.Remove(node);
			});
			this.RuleTypeCommand = new DelegateCommand<IList<ShipType>>(async delegate(IList<ShipType> list)
			{
				NavigationParameters parameters = new NavigationParameters
				{
					{
						"list",
						list
					}
				};
				await this.NavigationService.NavigateAsync("ShipTypeSelect", parameters);
			});
			this.RuleRemoveCommand = new DelegateCommand<RuleFleet>(delegate(RuleFleet node)
			{
				this.Task.RuleFleet.Remove(node);
			});
			this.FleetCommand = new DelegateCommand<IList<int>>(async delegate(IList<int> ship)
			{
				NavigationParameters parameters = new NavigationParameters
				{
					{
						"list",
						ship
					}
				};
				await this.NavigationService.NavigateAsync("ShipMultiSelect", parameters);
			});
			this.TacticsCommand = new DelegateCommand<IList<string>>(async delegate(IList<string> ship)
			{
				NavigationParameters parameters = new NavigationParameters
				{
					{
						"list",
						ship
					}
				};
				await this.NavigationService.NavigateAsync("TacticsSelect", parameters);
			});
			this.VisCommand = new DelegateCommand<RuleFleet>(new Action<RuleFleet>(this.OnVisCommandExecuted));
			this.EquipmentCommand = new DelegateCommand<RuleFleet>(async delegate(RuleFleet rule)
			{
				NavigationParameters parameters = new NavigationParameters
				{
					{
						"rule",
						rule
					}
				};
				await this.NavigationService.NavigateAsync("SelectEquipment", parameters);
			});
		}

		// Token: 0x060001D9 RID: 473 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x060001DA RID: 474 RVA: 0x00044735 File Offset: 0x00042935
		public void OnNavigatedTo(INavigationParameters parameters)
		{
			if (parameters.ContainsKey("task"))
			{
				this.Task = (AttackTask)parameters["task"];
			}
		}

		// Token: 0x060001DB RID: 475 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}

		// Token: 0x060001DC RID: 476 RVA: 0x0004475A File Offset: 0x0004295A
		private void OnVisCommandExecuted(RuleFleet node)
		{
			node.Type = ((node.Type == 2) ? 0 : (node.Type + 1));
		}

		// Token: 0x060001DD RID: 477 RVA: 0x00044778 File Offset: 0x00042978
		private async void OnUploadCommandExecuted()
		{
			if (string.IsNullOrWhiteSpace(this.Task.Author) || string.IsNullOrWhiteSpace(this.Task.Memo))
			{
				await this.PageDialogService.DisplayAlertAsync("提示", "必须填写作者及说明", "确定");
			}
			else
			{
				TaskAwaiter<bool> taskAwaiter = this.PageDialogService.DisplayAlertAsync("提示", "是否上传配置？", "确定", "取消").GetAwaiter();
				if (!taskAwaiter.IsCompleted)
				{
					await taskAwaiter;
					TaskAwaiter<bool> taskAwaiter2;
					taskAwaiter = taskAwaiter2;
					taskAwaiter2 = default(TaskAwaiter<bool>);
				}
				if (taskAwaiter.GetResult())
				{
					await Runtime.Remote.UploadTask(this.Task);
					await this.PageDialogService.DisplayAlertAsync("提示", "上传配置成功！", "确定");
				}
			}
		}

		// Token: 0x060001DE RID: 478 RVA: 0x000447B1 File Offset: 0x000429B1
		private void OnAddRuleCommandExecuted()
		{
			this.Task.RuleFleet.Add(new RuleFleet());
		}

		// Token: 0x060001DF RID: 479 RVA: 0x000447C8 File Offset: 0x000429C8
		private async void OnRemoveNodeCommandExecuted()
		{
			TaskAwaiter<bool> taskAwaiter = this.PageDialogService.DisplayAlertAsync("提示", "是否删除任务？", "确定", "取消").GetAwaiter();
			if (!taskAwaiter.IsCompleted)
			{
				await taskAwaiter;
				TaskAwaiter<bool> taskAwaiter2;
				taskAwaiter = taskAwaiter2;
				taskAwaiter2 = default(TaskAwaiter<bool>);
			}
			if (taskAwaiter.GetResult())
			{
				this.Game.AttackTasks.Remove(this.Task);
				this.Game.RemoveAttackTaskConfig(this.Task);
				await this.NavigationService.GoBackAsync();
			}
		}
	}
}
